import { categoryList } from '@/api/category'

const state = {
  category: [],
  nowCategory: { CategoryId: null, CategoryName: null }
}

const mutations = {
  SET_CATEGORY(state, category) {
    state.category = category
  },
  SET_NOWCATEGORY(state, nowCategory) {
    state.nowCategory = nowCategory
  }
}

const actions = {
  async getCategory({ commit }) {
    try {
      const category = await categoryList()
      commit('SET_CATEGORY', category)
    } catch (error) {
      commit('SET_CATEGORY', [])
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
